/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package restaurante.sessionbeans;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import restaurante.entidades.Comprobante;

/**
 *
 * @author omar
 */
@Stateless
public class ComprobanteFacade extends AbstractFacade<Comprobante> implements ComprobanteFacadeLocal {
    @PersistenceContext(unitName = "RestauranteEJB-ejbPU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public ComprobanteFacade() {
        super(Comprobante.class);
    }
    
    @Override
    public int obtenerCorrelativo() {
        Query qry = em.createQuery("Select max(c.idcomprobante) from Comprobante c");
        if (qry.getSingleResult() == null) {
            return 1;
        } else {
            return Integer.parseInt(qry.getSingleResult().toString()) + 1;
        }
    }
    
}
